package com.controller;


import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.controller.abstracts.AbstractController;
import com.internal.fileDataModel.TreeDirectory;
import com.internal.scan.ScanFileSystem;
import com.lastfm.handler.ArtistHandler;
import com.lastfm.search.Search;


@Controller
public class MainController extends AbstractController{
	
	final static org.slf4j.Logger log = LoggerFactory.getLogger(MainController.class);
	
	@RequestMapping(value = { "/info" },method = RequestMethod.GET)
	public ModelAndView index() throws InterruptedException, ExecutionException, IOException{
		log.info("Test");
		ModelAndView model = new ModelAndView();
		dispatcher.execute(new ScanFileSystem(system.getPath()));
		log.info(dispatcher.getResult().toString());
		TreeDirectory result  = (TreeDirectory)dispatcher.getResult();
		model.addObject("result", result.lista());
		model.setViewName("info");
		Search s = new Search();
		ArtistHandler artist = new ArtistHandler("Ella");
		artist.setApi_key("ec0251ff5bd36829e4de592c2bfe1ea9");
		String r = s.execute(artist);
		log.info(r);
		return model;
	}

}
